#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include "RBTree.h"
namespace sk
{
	template<class K, class V>
	class MyMap
	{
	public:
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};

		typedef typename RBTree<K, pair<K, V>, MapKeyOfT>::_iterator iterator;

		iterator begin()
		{
			return _t.begin();
		}
		iterator end()
		{
			return _t.end();
		}

		pair<iterator, bool> insert(const pair<K, V>& kv)
		{
			return _t.Insert(kv);
		}
		iterator find(const K& key)
		{
			return _t.Find(key);
		}
		V& operator[](const K& key)
		{
			auto ret = (_t.Insert(make_pair(key, V()))).first;
			return ret->second;
		}
	private:
		RBTree<K, pair<K, V>, MapKeyOfT> _t;
	};
	void MapTest()
	{
		MyMap<string, int> m;
		
		m.insert(make_pair("1", 1));
		m.insert(make_pair("1", 1));
		m.insert(make_pair("1", 1));
		m.insert(make_pair("1", 1));
		m.insert(make_pair("1", 1));
		m["5"] = 5;
		m["6"];
		MyMap<string, int> m2(m);
		MyMap<string, int> m3 = m2;
		MyMap<string, int>::iterator it = m.begin();
		cout << "map: " << endl;
		for (auto& e : m3)
		{
			cout << e.first << ":" << e.second << endl;
		}
	}
}